{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 作业: 非参数统计  李东-71230428"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "12家连锁店数据:\n",
    "星期二 456 207 139 246 177 212 195 170 184 163 225 236  \n",
    "星期日 440 391 210 130 180 210 150 220 237 360 550 452  \n",
    "圣诞节 320 840 430 340 200 300 130 180 156 240 780 630  \n",
    "用什么方法可以回答圣诞节与周末间有关系吗?  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/python3\n",
    "# -*- coding: utf-8 -*-\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.stats import shapiro\n",
    "from scipy.stats import binom\n",
    "\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_of_weekday = np.array([456,207,139,246,177,212,195,170,184,163,225,236])\n",
    "data_of_weekend = np.array([440,391,210,130,180,210,150,220,237,360,550,452])\n",
    "data_of_holiday = np.array([320,840,430,340,200,300,130,180,156,240,780,630])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 观察柱形图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([4., 1., 3., 0., 1., 0., 0., 1., 0., 2.]),\n",
       " array([130., 201., 272., 343., 414., 485., 556., 627., 698., 769., 840.]),\n",
       " <a list of 10 Patch objects>)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAA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LFruKnVMOgKq6uaqeS/OG7UlVtRHYAtxdzbAlVwC/BLwUOC/Jm2jGerxszG2WJGk5eI7tMe8UT4kkq4FH0AwQ/vKqurWdRWdumVU0j17ggbPjQPMSwMg/D7wnyd00V7F/364/jOaR0enAjTRXvZ+gCdqP7MbvSZK0bDzHCrxTPE32Ar4IPL2q3tmu22egzNHA3wJXATcPbFsHXDj4wsA8Lw/M91hmHQ+8il2X5HXAxcCrq+r/VtX2qjqdZliZF+5mWyVJWk6eY+XkHV2TZKaqbp1n/X7Av1bVYv2dduV31gAPrarbx3E8SZImnefYbjMpliRJUu/ZfUKSJEm9Z1IsSZKk3jMpliRJUu+ZFEuSJKn3TIolSZLUe/8f0io4WENPz0AAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 864x216 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(12, 3), sharex=True)\n",
    "ax1.set_title('平时', fontsize=16)\n",
    "ax1.set_xlabel('销售额', fontsize=16)\n",
    "ax2.set_title('周末', fontsize=16)\n",
    "ax3.set_xlabel('销售额', fontsize=16)\n",
    "ax3.set_title('圣诞', fontsize=16)\n",
    "ax3.set_xlabel('销售额', fontsize=16)\n",
    "ax1.hist(data_of_weekday)\n",
    "ax2.hist(data_of_weekend)\n",
    "ax3.hist(data_of_holiday)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "肉眼看去都不符合正态分布的特征"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### W正态性检验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周末: W值= 0.9029940366744995 , P值= 0.17337282001972198\n",
      "圣诞: W值= 0.8573182225227356 , P值= 0.045254744589328766\n"
     ]
    }
   ],
   "source": [
    "(W1, P1) = shapiro(data_of_weekend)\n",
    "(W2, P2) = shapiro(data_of_holiday)\n",
    "print('周末: W值=', W1, \", P值=\", P1)\n",
    "print('圣诞: W值=', W2, \", P值=\", P2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "圣诞销售数据计算出的P-Value = 0.045 < $\\alpha$ = 0.05, 拒绝正态性的假设, 接受圣诞节销售数据分布不是正态分布的备择假设."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 符号检验"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设检验:  \n",
    "&emsp; H0: 销售额(周末) $ = $  销售额(圣诞节)   \n",
    "&emsp; H1: 销售额(周末) $ \\neq $ 销售额(圣诞节)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数量(圣诞>周末) = 7 , 数量(圣诞<周末) = 5 , n = 12 , C = 0.5\n"
     ]
    }
   ],
   "source": [
    "# 圣诞销售 大于 周末销售 的个数\n",
    "s_1 = sum(data_of_holiday > data_of_weekend)\n",
    "# 圣诞销售 小于 周末销售 的个数\n",
    "s_2 = sum(data_of_holiday < data_of_weekend)\n",
    "n = s_1 + s_2\n",
    "if s_1 < n/2:\n",
    "    C = -0.5\n",
    "else:\n",
    "    C = 0.5\n",
    "print(\"数量(圣诞>周末) =\", s_1, \", 数量(圣诞<周末) =\", s_2, \", n =\", n, \", C =\", C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$ Z = \\dfrac{S^{+} - \\dfrac{n}{2} + C}{\\sqrt{\\dfrac{n}{4}}} \\overset{}{\\rightarrow} N(0,1) $\n",
    "\n",
    "代入公司得: Z = 0.866 < 1.96 ($\\alpha = 0.05$) 不能拒绝H0, 说明不存在明显相关关系"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "--------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "假设检验:  \n",
    "&emsp; H0: $ 销售额(周末)_{75\\%}  =   销售额(圣诞节)_{75\\%} $   \n",
    "&emsp; H1: $ 销售额(周末)_{75\\%} \\neq  销售额(圣诞节)_{75\\%} $   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P =  4.2915344238281114e-06\n"
     ]
    }
   ],
   "source": [
    "holiday_75 = np.percentile(data_of_holiday, 75)\n",
    "P = 2 * binom.pmf(sum(data_of_weekend > holiday_75), 12, 0.75)\n",
    "# P = 2 * binom.pmf(sum(data_of_weekend < holiday_75), 12, 0.25)\n",
    "print(\"P = \", P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "算出来P值 < $\\alpha = 0.01$, 拒绝H0, 接受销售额在周末和圣诞节期间3/4的分位值是不相同的."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
